import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/viewmodel/meal/add_meal_view_model.dart';

class AddMealPage extends BaseStatefulMvvmWidget {
  final ElderInfo? info;

  AddMealPage({this.info});

  @override
  State<StatefulWidget> createState() => _AddMealState();
}

class _AddMealState extends BaseMvvmState<AddMealViewModel, AddMealPage> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        ListView(
          children: [
            IconTitleTextWidget(
              "长者姓名",
              hintText: "请选择",
              text: viewModel.older?.name ?? "",
            ).onTap(() {
              if (widget.info == null) {
                viewModel.selectOlder();
              }
            }),
            Gaps.line,
            IconTitleTextWidget(
              "用餐时间",
              hintText: "请选择",
              text: viewModel.mealTime,
            ).onTap(() {
              viewModel.selectMealTime();
            }),
            Gaps.line,
            IconTitleTextWidget(
              "用餐时段",
              hintText: "请选择",
              text: viewModel.timeRangeName,
            ).onTap(() {
              viewModel.selectFoodType();
            }),
            Gaps.midLine,
            Row(
              children: [
                CommonText('菜品名称  '),
                CommonText(viewModel.selectFood, textAlign: TextAlign.end)
                    .setWeight(1)
              ],
            ).addToContainer(
                margin: EdgeInsets.symmetric(horizontal: 16, vertical: 15)),
            Gaps.line,
            GridView.count(
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              crossAxisCount: 3,
              children: viewModel.foodWidgets,
              crossAxisSpacing: 10,
              mainAxisSpacing: 10,
            ).addToContainer(margin: EdgeInsets.all(16))
          ],
        ).setWeight(1),
        ElevatedButton(
          onPressed: () {
            viewModel.submitMeal();
          },
          child: CommonText('提交', textSize: 17, textColor: Colors.white),
          style: ButtonStyles.submit_btn_style,
        ).addToContainer(
            margin: EdgeInsets.only(left: 16, right: 16, bottom: 16))
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text("新增饮食信息"),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  AddMealViewModel createViewModel() {
    return AddMealViewModel(context, info: widget.info);
  }

  @override
  void onRetryClick() {}
}
